﻿using CommunityToolkit.Mvvm.Messaging;
using Enterprises.Wpf.Sample.Data;
using Enterprises.Wpf.Sample.Messages;
using HandyControl.Tools.Extension;
using HandyControl.Tools;
using System.Windows;

namespace Enterprises.Wpf.Sample.UserControls.Main
{
    /// <summary>
    /// MainContent.xaml 的交互逻辑
    /// </summary>
    public partial class MainContent
    {
        public MainContent()
        {
            InitializeComponent();

            WeakReferenceMessenger.Default.Register<FullSwitchMessage, string>(this, MessageToken.FullSwitch, FullSwitch);
        }

        private bool _isFull;
        /// <summary>
        /// 全屏消息处理
        /// </summary>
        /// <param name="recipient"></param>
        /// <param name="message"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void FullSwitch(object recipient, FullSwitchMessage message)
        {
            bool isFull = message.FullSwitch;
            if (_isFull == isFull)
            {
                return;
            }

            _isFull = isFull;

            if (_isFull)
            {
                BorderRootEffect.Show();
                BorderEffect.Collapse();
                BorderTitle.Collapse();
                GridMain.HorizontalAlignment = HorizontalAlignment.Stretch;
                GridMain.VerticalAlignment = VerticalAlignment.Stretch;
                PresenterMain.Margin = new Thickness();
                BorderRoot.CornerRadius = new CornerRadius(10);
                BorderRoot.Style = ResourceHelper.GetResource<Style>("BorderClip");
            }
            else
            {
                BorderRootEffect.Collapse();
                BorderEffect.Show();
                BorderTitle.Show();
                GridMain.HorizontalAlignment = HorizontalAlignment.Center;
                GridMain.VerticalAlignment = VerticalAlignment.Center;
                PresenterMain.Margin = new Thickness(0, 0, 0, 10);
                BorderRoot.CornerRadius = new CornerRadius();
                BorderRoot.Style = null;
            }
        }
    }
}
